package com.zui.util;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//testJQGridFilter();
		String splitString= "parentCatalog.catalogName";
		String[] strArray = splitString.split("\\.");
		System.out.println(strArray);
	}
	
	/**
	 * 
	 */
	public static void testJQGridFilter() {
		String filters = "{\"groupOp\":\"AND\",\"rules\":[{\"field\":\"catalogName\",\"op\":\"bw\",\"data\":\"200\"}]},{\"field\":\"parentCatalog.catalogName\",\"op\":\"bw\",\"data\":\"11\"}]}";

		String[] filterArray = filters.split("[{}]", -1);
		JQGridFilter jqFilter = new JQGridFilter();
		
		
		for(String filter:filterArray) {
			if (filter.contains("groupOp")) {
				jqFilter.setGroupOp(filters.substring(filters.indexOf("\"groupOp\":")+11, filters.indexOf(",\"rules\"")-1));
			} else if (filter.contains("field")) {
				String searchField = filter.substring(filter.indexOf("\"field\":") + 9,
						filter.indexOf("\"op\":") - 2);
				String op = filter.substring(filter.indexOf("\"op\":") + 6,
						filter.indexOf("\"data\":") - 2);
				String data = filter.substring(filter.indexOf("\"data\":") + 8,
						filter.lastIndexOf("\""));
				
				jqFilter.addRule(new JQGridFilterRule(searchField, op, data));
			}
		}
		
		System.out.print(jqFilter);
	}

}
